package org.mch.func.db.conn;

import java.io.Serializable;

/**
 * 描述：数据库连接信息；
 * 
 * @author MCH；Date：2008-10-01；<BR/>
 * 
 */
public class DBConnInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String OracleDriver = "oracle.jdbc.driver.OracleDriver";
	public static final String DB2Driver = "";
	public static final String MySQL5Driver = "com.mysql.jdbc.Driver";
	public static final String SQLServer2000Driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	public static final String SQLServer2005Driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	public static final String PostgreSQL8_3Driver = "org.postgresql.Driver";
	private int dbtype;
	private String databasename;
	private String address;
	private String port_str;
	private String username;
	private String password;

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getDatabasename() {
		if ((this.databasename == null) || (this.databasename.trim().equals(""))) {
			switch (this.dbtype) {
				case 2:
					return "master";
				case 3:
					return "master";
				case 4:
					return "information_schema";
				case 0:
					return "orcl";
				case 1:
			}
			return "没有找到当前数据库类型！";
		}

		return this.databasename;
	}

	public void setDatabasename(String databasename) {
		this.databasename = databasename;
	}

	public int getDbtype() {
		return this.dbtype;
	}

	public void setDbtype(int dbtype) {
		this.dbtype = dbtype;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPort_str() {
		return this.port_str;
	}

	public void setPort_str(String port_str) {
		this.port_str = port_str;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getDriver() {
		switch (this.dbtype) {
			case 0:
				return "oracle.jdbc.driver.OracleDriver";
			case 2:
				return "com.microsoft.jdbc.sqlserver.SQLServerDriver";
			case 3:
				return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
			case 4:
				return "com.mysql.jdbc.Driver";
			case 5:
				return "org.postgresql.Driver";
		}
		return null;
	}

	public String getURL() {
		switch (this.dbtype) {
			case 0:
				return "jdbc:oracle:thin:@" + getAddress() + ":" + getPort_str() + ":" + getDatabasename();
			case 2:
				return "jdbc:microsoft:sqlserver://" + getAddress() + ":" + getPort_str() + ";databasename=" + getDatabasename();
			case 3:
				return "jdbc:sqlserver://" + getAddress() + ":" + getPort_str() + ";databasename=" + getDatabasename();
			case 4:
				return "jdbc:mysql://" + getAddress() + ":" + getPort_str() + "/" + getDatabasename() + "?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull";
			case 5:
				return "jdbc:postgresql://" + getAddress() + ":" + getPort_str() + "/" + getDatabasename();
			case 1:
		}
		return null;
	}
}